home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / progtool / c / egem_210 / egem / example / windemo / xacclook.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  6KB  |  291 lines

  1.  
  2. /* XAcc-Spion (läuft als Programm und als Accessory),
  3.    (c) 1994 C. Grunenberg */
  4.  
  5. #include <e_gem.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8.  
  9. #define MAX_LINE    512
  10. #define MINSIZE        160
  11. #define GADGETS        NAME|CLOSER|FULLER|MOVER|INFO|SIZER|UPARROW|DNARROW|VSLIDE|LFARROW|RTARROW|HSLIDE|SMALLER
  12.  
  13. typedef struct
  14. {
  15.     int scan,shift,norm;
  16. } KEY;
  17.  
  18. KEY scroll_keys[] = {
  19. {SCANUP,PAGE_UP,LINE_UP},
  20. {SCANDOWN,PAGE_DOWN,LINE_DOWN},
  21. {SCANLEFT,PAGE_LEFT,LINE_LEFT},
  22. {SCANRIGHT,PAGE_RIGHT,LINE_RIGHT},
  23. {SCANHOME,WIN_END,WIN_START} };
  24.  
  25. SCROLL scroll;
  26. WIN *window;
  27.  
  28. char *entry = "  XAccSearch",*title = "XAccSearch",info[64];
  29. char *xacc_name = "XAccSearch",*av_name = "XACCLOOK";
  30.  
  31. XAcc *app[128];
  32. int app_cnt;
  33.  
  34. char textline[MAX_LINE+128],xdsc[MAX_LINE];
  35. char xacc_info[] = "  Name                 Ap-ID  Menu-ID    Version    Groups  Extended Features";
  36. char xacc_sub[]  = " -----------------------------------------------------------------------------";
  37. char xacc_out[] = "  %-20s%4d%8d%6d.%d ($%02x,%2d) %s  %s";
  38. char xacc_groups[] = "av____";
  39.  
  40. int make_info(XAcc *xacc)
  41. {
  42.     reg char c,*name = (xacc->xname!=NULL) ? xacc->xname : xacc->name,*p,*q;
  43.     reg int version = xacc->version>>8,low = 0,high,i,bit;
  44.  
  45.     if (version>=0x30 && version<=0x39)
  46.         high = version - 0x30;
  47.     else if (version>=0x10)
  48.     {
  49.         high = version>>4;
  50.         low = version & 0xf;
  51.     }
  52.     else
  53.         high = version;
  54.  
  55.     p = xacc_groups;
  56.     *p++ = (xacc->flag & AV) ? 'A' : '_';
  57.     *p++ = (xacc->flag & XACC) ? 'X' : '_';
  58.     for (i=4,bit=(1<<3);--i>=0;bit>>=1)
  59.         *p++ = (xacc->version & bit) ? i+'1' : '_';
  60.  
  61.     p = xdsc;
  62.     if ((q=xacc->xdsc)!=NULL)
  63.     {
  64.         for (;;)
  65.         {
  66.             q++;
  67.             while ((c=*q++)!='\0')
  68.                 *p++ = c;
  69.             if (*q)
  70.                 *p++ = ' ';
  71.             else
  72.                 break;
  73.         }
  74.     }
  75.     *p = '\0';
  76.  
  77.     return (sprintf(textline,xacc_out,name,xacc->id,xacc->menu_id,high,low,version,version,xacc_groups,xdsc));
  78. }
  79.  
  80. void Draw(WIN *win,GRECT *area)
  81. {
  82.     reg SCROLL *sc = win->scroll;
  83.     reg XAcc **xacc_lst;
  84.     reg char c,*text;
  85.     reg int char_cnt,x,y = win->work.g_y,d_x = 120*gr_cw;
  86.     int start_line,lines;
  87.  
  88.     v_set_mode(MD_XOR);
  89.     v_set_text(ibm_font_id,ibm_font,BLACK,NULL);
  90.     rc_sc_clear(area);
  91.  
  92.     start_line = (area->g_y - y)/gr_ch;
  93.     y += start_line*gr_ch;
  94.     start_line += sc->vpos;
  95.     xacc_lst = &app[max(start_line-3,0)];
  96.  
  97.     lines = min((area->g_y - y + area->g_h + gr_ch - 1)/gr_ch,scroll.vsize-start_line);
  98.     for (;--lines>=0;y+=gr_ch,start_line++)
  99.     {
  100.         switch (start_line)
  101.         {
  102.         case 0:
  103.             continue;
  104.         case 1:
  105.             text = xacc_info;
  106.             char_cnt = (int) sizeof(xacc_info);
  107.             break;
  108.         case 2:
  109.             text = xacc_sub;
  110.             char_cnt = (int) sizeof(xacc_sub);
  111.             break;
  112.         default:
  113.             text = textline;
  114.             char_cnt = make_info(*xacc_lst++);
  115.         }
  116.  
  117.         x = win->work.g_x;
  118.         text += sc->hpos;
  119.         char_cnt -= sc->hpos;
  120.  
  121.         while (char_cnt>0)
  122.         {
  123.             text += 120;
  124.             c = *text;
  125.             *text = '\0';
  126.             v_gtext(x_handle,x,y,text-120);
  127.             *text = c;
  128.  
  129.             char_cnt -= 120;
  130.             x += d_x;
  131.         }
  132.     }
  133. }
  134.  
  135. void error(int icon,char *msg)
  136. {
  137.     xalert(1,1,icon,NULL,SYS_MODAL,BUTTONS_RIGHT,TRUE,title,msg,"[Got it!");
  138. }
  139.  
  140. void SetWindow(void)
  141. {
  142.     scroll.hsize = MAX_LINE;
  143.     scroll.vsize = app_cnt+3;
  144.     scroll.px_hline = gr_cw;
  145.     scroll.px_vline = gr_ch;
  146.     scroll.hscroll = scroll.vscroll = 1;
  147.  
  148.     if (app_cnt)
  149.         sprintf(info," %d XAcc-/AV-Applikation(en) gefunden.",app_cnt);
  150.     else
  151.         strcpy(info," Keine XAcc-/AV-Applikationen.");
  152. }
  153.  
  154. void CloseWindow(void)
  155. {
  156.     if (window)
  157.     {
  158.         close_window(window,FALSE);
  159.         window = NULL;
  160.         if (!_app)
  161.             MouseArrow();
  162.     }
  163.  
  164.     if (_app)
  165.         exit_gem(0);
  166. }
  167.  
  168. void OpenWindow(void)
  169. {
  170.     SetWindow();
  171.     window = open_window(title,NULL,info,NULL,GADGETS,FALSE,MINSIZE,MINSIZE,NULL,&desk,&scroll,Draw);
  172.     if (window==NULL)
  173.     {
  174.         error(X_ICN_ALERT,"No more windows available!");
  175.         CloseWindow();
  176.     }
  177.     else
  178.         window_set_mouse(window,TEXT_CRSR,ARROW,NULL,NULL);
  179. }
  180.  
  181. int InitEvent(XEVENT *ev,int avail)
  182. {
  183.     int flags = MU_MESAG|MU_KEYBD;
  184.  
  185.     if (window)
  186.     {
  187.         if (window->inside>=0 && (avail & MU_M1))
  188.         {
  189.             ev->ev_mm1flags = window->inside;
  190.             *(GRECT *) &ev->ev_mm1x = window->work;
  191.             flags |= MU_M1;
  192.         }
  193.     }
  194.  
  195.     return (flags & avail);
  196. }
  197.  
  198. int Event(XEVENT *ev)
  199. {
  200.     int *msg,wich = ev->ev_mwich,scan,state,used=0,i,k;
  201.     KEY *keys;
  202.  
  203.     if (wich & MU_M1)
  204.     {
  205.         window_mouse(window);
  206.         used |= MU_M1;
  207.     }
  208.  
  209.     if (wich & MU_MESAG)
  210.     {
  211.         msg = ev->ev_mmgpbuf;
  212.         used |= MU_MESAG;
  213.  
  214.         switch (msg[0])
  215.         {
  216.         case AC_OPEN:
  217.             OpenWindow();
  218.             break;
  219.         case AC_CLOSE:
  220.         case AP_TERM:
  221.         case WM_CLOSED:
  222.             CloseWindow();
  223.             break;
  224.         case WM_TOPPED:
  225.             window_top(window);
  226.             break;
  227.         case WM_BOTTOMED:
  228.             window_bottom(window);
  229.             break;
  230.         case WM_FULLED:
  231.             *(GRECT *) &msg[4] = (window->fulled) ? window->prev : window->max;
  232.         case WM_SIZED:
  233.         case WM_MOVED:
  234.             window_size(window,(GRECT *) &msg[4]);
  235.             break;
  236.         case XACC_AV_INIT:
  237.         case XACC_AV_EXIT:
  238.             app_cnt = 0;
  239.             i = 1;
  240.             while ((app[app_cnt++]=find_app(i))!=NULL)
  241.                 i = 0;
  242.             app_cnt--;
  243.             SetWindow();
  244.             if (window)
  245.                 window_reinit(window,title,NULL,info,FALSE);
  246.             break;
  247.         default:
  248.             used &= ~MU_MESAG;
  249.         }
  250.     }
  251.  
  252.     if ((wich & MU_KEYBD) && window!=NULL)
  253.     {
  254.         k = scan_2_ascii(scan=ev->ev_mkreturn,state=ev->ev_mmokstate);
  255.         if (state & K_CTRL)
  256.         {
  257.             if (k=='Q')
  258.             {
  259.                 used |= MU_KEYBD;
  260.                 CloseWindow();
  261.             }
  262.         }
  263.         else
  264.             for (keys=&scroll_keys[0],i=0,scan>>=8;i<sizeof(scroll_keys);i++,keys++)
  265.                 if (keys->scan==scan)
  266.                 {
  267.                     scroll_window(window,(state & (K_RSHIFT|K_LSHIFT)) ? keys->shift : keys->norm,NULL);
  268.                     used |= MU_KEYBD;
  269.                     break;
  270.                 }
  271.     }
  272.  
  273.     return (used);
  274. }
  275.  
  276. void main(void)
  277. {
  278.     if (init_gem(entry,xacc_name,av_name,0,0,0)==TRUE)
  279.     {
  280.         scroll.scroll = TRUE;
  281.  
  282.         Event_Handler(InitEvent,Event);
  283.         if (_app)
  284.         {
  285.             Event_Timer(500,0);
  286.             OpenWindow();
  287.         }
  288.         Event_Multi(NULL);
  289.     }
  290. }
  291.